#include "ipv6.h"
#include <string.h>


/* ----------------------------------------------------- */
/* get IPv4/IPv6 address                                 */
/* ----------------------------------------------------- */


int
get_ip_address(sa, host, hostlen)
  const struct sockaddr *sa;
  char *host;
  size_t hostlen;
{
  char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
  int ret;

  if ((ret = getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf,
	sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) != 0)
    return ret;		/* could not get hostname */

  strncpy(host, hbuf, hostlen);
  host[--hostlen] = '\0';

#if 0
  /* sby: Since we bind two sockets (IPv6/IPv4),
   * getnameinfo() will not return IPv4-mapped IPv6 addresses */
  if (strstr(host, "::ffff:"))
    strcpy(host, host + 7);
#endif

  return ret;
}

